<?php	

/* ---------------------------------------
RECENT POSTS WIDGET
--------------------------------------- */
class show_recent extends WP_Widget {
	function show_recent() {
		$widget_ops = array('classname' => 'show_recent', 'description' => __('Show your recent posts.'));
		$this->WP_Widget('show_recent', 'ARCHITEC - Recent Posts', $widget_ops);
	}

	function widget($args, $instance){
		extract($args);

		//$options = get_option('custom_recent');
		$title = $instance['title'];
		$posts = $instance['posts'];

		//GET the posts
		global $post;
		$exclude = B_getExcludedCats();
		$myposts = get_posts('numberposts='.$posts.'&offset=0&category='.$exclude);
		
		echo $before_widget . $before_title . $title . $after_title;


		//SHOW the posts
		foreach($myposts as $post){
			setup_postdata($post);
//added strip_tags to solve a problem with code being displayed improperly.
			?>
		<div class="recent_post">
			<div class="imgpost">
				<a href="<?php the_permalink() ?>"/>
					<img alt="<?php the_title() ?>" src="<?php echo wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); ?>"/>
				</a>
			</div>
			<div class="txtpost">
				<h4><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h4>
				<p><a href="<?php the_permalink() ?>"><?php echo substr(strip_tags($post->post_content), 0, 125); ?>...</a></p>
			</div>
			
        </div><!-- end footer_post -->
			<?php
		}
		echo $after_widget;
	}

	function update($newInstance, $oldInstance){
		$instance = $oldInstance;
		$instance['title'] = strip_tags($newInstance['title']);
		$instance['posts'] = $newInstance['posts'];

		return $instance;
	}

	function form($instance){
		echo '<p><label for="'.$this->get_field_id('title').'">' . 'Title:' . '</label><input class="widefat" id="'.$this->get_field_id('title').'" name="'.$this->get_field_name('title').'" type="text" value="'.$instance['title'].'" /></p>';

		echo '<p><label for="'.$this->get_field_id('posts').'">' . 'Number of Posts:', 'widgets' . '</label><input class="widefat" id="'.$this->get_field_id('posts').'" name="'.$this->get_field_name('posts').'" type="text" value="'.$instance['posts'].'" /></p>';

		echo '<input type="hidden" id="custom_recent" name="custom_recent" value="1" />';
	}
}

add_action('widgets_init', create_function('', 'return register_widget("show_recent");'));

?>